package com.SinaMicrobloggingAPI.Core.Request;

import java.io.DataInputStream;
import java.io.InputStream;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.*;

import com.SinaMicrobloggingAPI.Core.OauthConstants;
import com.SinaMicrobloggingAPI.Core.Response.IResponse;

public class AuthorizeRequest extends RequestBase {

	private static final String AUTHORIZE = "Authorize";
	

	private String userId;
	private String password;

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Override
	protected String getRequestName() {
		// TODO Auto-generated method stub
		return AUTHORIZE;
	}

	public AuthorizeRequest(IResponse response) {
		super(response);
	}

	protected String getRequestParamenters() {

		BasicNameValuePair oauth_token = new BasicNameValuePair(
				OauthConstants.OAUTH_TOKEN_KEY, getOauthToken());
		BasicNameValuePair oauth_callback = new BasicNameValuePair(
				OauthConstants.OAUTH_CALLBACK_KEY, String.format(
						"%s&action=submit", CALLBACK));
		BasicNameValuePair userId = new BasicNameValuePair(
				OauthConstants.USER_ID_KEY, getUserId());
		BasicNameValuePair password = new BasicNameValuePair(
				OauthConstants.PASSWORD_KEY, getPassword());

		oauthParamenterModels.add(oauth_token);
		oauthParamenterModels.add(oauth_callback);
		oauthParamenterModels.add(userId);
		oauthParamenterModels.add(password);

		return buildParamenters();
	}
	/*
	 * public IResponse getResponse() {
	 * 
	 * String requestUrl = getRequestUrlWithNoParamenters(); HttpClient
	 * httpclient = new DefaultHttpClient(); HttpPost httpPost = new
	 * HttpPost(requestUrl);
	 * 
	 * try { StringBody userId = new StringBody(getUserId()); StringBody
	 * password = new StringBody(getPassword()); StringBody oauthToken = new
	 * StringBody(super.getOauthToken()); StringBody oauthTokenSecret = new
	 * StringBody(super .getOauthTokenSecret()); StringBody oauthTokenCallback =
	 * new StringBody(CALLBACK); MultipartEntity reqEntity = new
	 * MultipartEntity();
	 * 
	 * reqEntity.addPart(OauthConstants.USER_ID_KEY, userId);
	 * reqEntity.addPart(OauthConstants.PASSWORD_KEY, password);
	 * reqEntity.addPart(OauthConstants.OAUTH_TOKEN_KEY, oauthToken);
	 * reqEntity.addPart(OauthConstants.OAUTH_TOKEN_SECRET_KEY,
	 * oauthTokenSecret); reqEntity.addPart(OauthConstants.OAUTH_CALLBACK_KEY,
	 * oauthTokenCallback); httpPost.setEntity(reqEntity); HttpResponse
	 * httpResponse = httpclient.execute(httpPost); HttpEntity entity =
	 * httpResponse.getEntity();
	 * 
	 * if (entity != null) { String result = EntityUtils.toString(entity);
	 * response.ParseResult(result.replaceAll("\r", ""));
	 * httpclient.getConnectionManager().shutdown(); } } catch (Exception ex) {
	 * httpPost.abort(); throw new RuntimeException(ex); }
	 * 
	 * return response; }
	 */

}
